QuickOPC User's Guide and Reference
.NET and Python Examples
Examples > Examples in the Product and on the Web > .NET and Python Examples
In This Topic

For the very simplest, introductory examples, see these pages on our main Web site: 

The .NET examples are currently provided for Microsoft Visual Studio 2022. Some examples can also be used with .NET 6 or 7 or .NET CLI Tools, JetBrain Rider, and Visual Studio Code. They are likely to work with other development tools as well, but we have not tested it.

The examples are targeting Microsoft .NET Framework 4.7.2 (and will also run under newer versions), and/or .NET 6 or 7. In Visual Studio, it is possible to re-target the projects to newer framework versions (e.g.  4.8) by changing the appropriate setting in the properties of the project, or by editing the project file manually.

Python examples were originally tested in CPython 3.6.2 with pythonnet 2.5.2, and CPython 3.11.5 with pythonnet 3.0.2.

On Windows, if you have used the Setup Program to install QuickOPC, Visual Studio solutions with examples in Visual Basic (i.e. VB.NET), C#, F# and C++ are available from the Start menu or the Launcher application. On other platforms (or when you are simply installing the QuickOPC NuGet Packages or Python Packages), you are advised to download the example archives from the Web and unpack them on your computer. This is described further below.

Example NuGet Packages

Some examples (those from the DocExamples and UADocExamples projects, in C# and VB.NET) are also distributed (with source code) in form of NuGet packages, on www.nuget.org . The packages are:

The strings in bold are the package IDs.

Using The Example Packages

The Example Package is not a runnable project on its own. It just contains pieces of source code that you can call or copy into your own project.

In order to run the code from console-based example packages, you need to call it from your project. The examples are organized by the OPC specification, and each example is a static method that you can directly invoke. For easier exploration, there are also methods that provide the user with a menu of methods to choose from.

Alternatively, you can call just a single selected example, e.g. for reading an OPC UA node, call the UADocExamples._EasyUAClient.Read.Main1 method.

Example Archives

Examples for .NET can be downloaded directly from the Web, in form of archive (.TGZ or .ZIP) files. This distribution method can be used without running any installer, on all operating systems. The archive files available are:

Note: F# examples are only available for .NET 6+. You can, however, use the same F# source files in .NET Framework, and recreate the example project in .NET Framework, if you need.

The examples are delivered in source form only. If you want to run them, having installed the proper .NET runtime is not enough - you also need the corresponding SDK. For .NET 6 or 7:

Retrieving the Example Archives

In order to use the example archives, first download them to your system, and extract the files from the archive. With a GUI on Windows, you can download the files using a Web browser, and uncompress the .ZIP with built-in Windows Explorer (shell) commands. You may have similar features on your Linux, depending on what distribution you chose. If you don't, following commands can be used in the terminal to download and extract the archives (the URL and file names are just examples - replace them with the right ones if you need a different set of examples):

wget "http://cdn.opclabs.com/files/downloads/QuickOpc/2023.2/Examples-NET-CSharp.tgz"
tar -xvzf Examples-NET-CSharp.tgz

On macOS, and on Linux systems where wget is not available, you can use curl -O instead.

Working with the Examples

You can now open the solutions or projects from your IDE, view and modify their code, or run them.

If you just want to run the examples from the command line without inspecting their source code, first change your current directory to the project type of your choice, e.g.:

cd Console

Then, build and launch the chosen project, e.g.:

dotnet run --project UADocExamples/MultiTargetUADocExamples.csproj

or

dotnet run --project DocExamples/MultiTargetDocExamples.csproj

All QuickOPC project files for .NET 6+ start with prefix "MultiTarget". This is because there is also a second project over the same set of source files for .NET Framework, and a separate project file is needed for .NET 6+ due to differences in the project format. Make sure you do not confuse the two projects. For example, in .NET 6+, use "MultiTargetUADocExamples.csproj", and not "UADocExamples.csproj".

Categories

Following categories of .NET examples are available:

PowerShell Execution Policy

The default PowerShell settings only allow execution of scripts signed by a trusted authority. Use the following PowerShell command to enable execution of QuickOPC example scripts:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

 

See Also